(0) Obligation:

The Runtime Complexity (innermost) of the given CpxTRS could be proven to be BOUNDS(1, n^2).


The TRS R consists of the following rules:

half(0) → 0
half(s(0)) → 0
half(s(s(x))) → s(half(x))
inc(0) → 0
inc(s(x)) → s(inc(x))
zero(0) → true
zero(s(x)) → false
p(0) → 0
p(s(x)) → x
bits(x) → bitIter(x, 0)
bitIter(x, y) → if(zero(x), x, inc(y))
if(true, x, y) → p(y)
if(false, x, y) → bitIter(half(x), y)

Rewrite Strategy: INNERMOST

(1) TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID) transformation)

Transformed TRS to weighted TRS

(2) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^2).


The TRS R consists of the following rules:

half(0) → 0 [1]
half(s(0)) → 0 [1]
half(s(s(x))) → s(half(x)) [1]
inc(0) → 0 [1]
inc(s(x)) → s(inc(x)) [1]
zero(0) → true [1]
zero(s(x)) → false [1]
p(0) → 0 [1]
p(s(x)) → x [1]
bits(x) → bitIter(x, 0) [1]
bitIter(x, y) → if(zero(x), x, inc(y)) [1]
if(true, x, y) → p(y) [1]
if(false, x, y) → bitIter(half(x), y) [1]

Rewrite Strategy: INNERMOST

(3) TypeInferenceProof (BOTH BOUNDS(ID, ID) transformation)

Infered types.

(4) Obligation:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

half(0) → 0 [1]
half(s(0)) → 0 [1]
half(s(s(x))) → s(half(x)) [1]
inc(0) → 0 [1]
inc(s(x)) → s(inc(x)) [1]
zero(0) → true [1]
zero(s(x)) → false [1]
p(0) → 0 [1]
p(s(x)) → x [1]
bits(x) → bitIter(x, 0) [1]
bitIter(x, y) → if(zero(x), x, inc(y)) [1]
if(true, x, y) → p(y) [1]
if(false, x, y) → bitIter(half(x), y) [1]

The TRS has the following type information:
half :: 0:s → 0:s
0 :: 0:s
s :: 0:s → 0:s
inc :: 0:s → 0:s
zero :: 0:s → true:false
true :: true:false
false :: true:false
p :: 0:s → 0:s
bits :: 0:s → 0:s
bitIter :: 0:s → 0:s → 0:s
if :: true:false → 0:s → 0:s → 0:s

Rewrite Strategy: INNERMOST

(5) CompletionProof (UPPER BOUND(ID) transformation)

The TRS is a completely defined constructor system, as every type has a constant constructor and the following rules were added:
none

And the following fresh constants: none

(6) Obligation:

Runtime Complexity Weighted TRS where all functions are completely defined. The underlying TRS is:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

half(0) → 0 [1]
half(s(0)) → 0 [1]
half(s(s(x))) → s(half(x)) [1]
inc(0) → 0 [1]
inc(s(x)) → s(inc(x)) [1]
zero(0) → true [1]
zero(s(x)) → false [1]
p(0) → 0 [1]
p(s(x)) → x [1]
bits(x) → bitIter(x, 0) [1]
bitIter(x, y) → if(zero(x), x, inc(y)) [1]
if(true, x, y) → p(y) [1]
if(false, x, y) → bitIter(half(x), y) [1]

The TRS has the following type information:
half :: 0:s → 0:s
0 :: 0:s
s :: 0:s → 0:s
inc :: 0:s → 0:s
zero :: 0:s → true:false
true :: true:false
false :: true:false
p :: 0:s → 0:s
bits :: 0:s → 0:s
bitIter :: 0:s → 0:s → 0:s
if :: true:false → 0:s → 0:s → 0:s

Rewrite Strategy: INNERMOST

(7) CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID) transformation)

Transformed the TRS into an over-approximating RNTS by (improved) Size Abstraction.
The constant constructors are abstracted as follows:

0 => 0
true => 1
false => 0

(8) Obligation:

Complexity RNTS consisting of the following rules:

bitIter(z, z') -{ 1 }→ if(zero(x), x, inc(y)) :|: x >= 0, y >= 0, z = x, z' = y
bits(z) -{ 1 }→ bitIter(x, 0) :|: x >= 0, z = x
half(z) -{ 1 }→ 0 :|: z = 0
half(z) -{ 1 }→ 0 :|: z = 1 + 0
half(z) -{ 1 }→ 1 + half(x) :|: x >= 0, z = 1 + (1 + x)
if(z, z', z'') -{ 1 }→ p(y) :|: z' = x, z'' = y, z = 1, x >= 0, y >= 0
if(z, z', z'') -{ 1 }→ bitIter(half(x), y) :|: z' = x, z'' = y, x >= 0, y >= 0, z = 0
inc(z) -{ 1 }→ 0 :|: z = 0
inc(z) -{ 1 }→ 1 + inc(x) :|: x >= 0, z = 1 + x
p(z) -{ 1 }→ x :|: x >= 0, z = 1 + x
p(z) -{ 1 }→ 0 :|: z = 0
zero(z) -{ 1 }→ 1 :|: z = 0
zero(z) -{ 1 }→ 0 :|: x >= 0, z = 1 + x

Only complete derivations are relevant for the runtime complexity.

(9) CompleteCoflocoProof (EQUIVALENT transformation)

Transformed the RNTS (where only complete derivations are relevant) into cost relations for CoFloCo:

eq(start(V, V6, V9),0,[half(V, Out)],[V >= 0]).
eq(start(V, V6, V9),0,[inc(V, Out)],[V >= 0]).
eq(start(V, V6, V9),0,[zero(V, Out)],[V >= 0]).
eq(start(V, V6, V9),0,[p(V, Out)],[V >= 0]).
eq(start(V, V6, V9),0,[bits(V, Out)],[V >= 0]).
eq(start(V, V6, V9),0,[bitIter(V, V6, Out)],[V >= 0,V6 >= 0]).
eq(start(V, V6, V9),0,[if(V, V6, V9, Out)],[V >= 0,V6 >= 0,V9 >= 0]).
eq(half(V, Out),1,[],[Out = 0,V = 0]).
eq(half(V, Out),1,[],[Out = 0,V = 1]).
eq(half(V, Out),1,[half(V1, Ret1)],[Out = 1 + Ret1,V1 >= 0,V = 2 + V1]).
eq(inc(V, Out),1,[],[Out = 0,V = 0]).
eq(inc(V, Out),1,[inc(V2, Ret11)],[Out = 1 + Ret11,V2 >= 0,V = 1 + V2]).
eq(zero(V, Out),1,[],[Out = 1,V = 0]).
eq(zero(V, Out),1,[],[Out = 0,V3 >= 0,V = 1 + V3]).
eq(p(V, Out),1,[],[Out = 0,V = 0]).
eq(p(V, Out),1,[],[Out = V4,V4 >= 0,V = 1 + V4]).
eq(bits(V, Out),1,[bitIter(V5, 0, Ret)],[Out = Ret,V5 >= 0,V = V5]).
eq(bitIter(V, V6, Out),1,[zero(V7, Ret0),inc(V8, Ret2),if(Ret0, V7, Ret2, Ret3)],[Out = Ret3,V7 >= 0,V8 >= 0,V = V7,V6 = V8]).
eq(if(V, V6, V9, Out),1,[p(V10, Ret4)],[Out = Ret4,V6 = V11,V9 = V10,V = 1,V11 >= 0,V10 >= 0]).
eq(if(V, V6, V9, Out),1,[half(V12, Ret01),bitIter(Ret01, V13, Ret5)],[Out = Ret5,V6 = V12,V9 = V13,V12 >= 0,V13 >= 0,V = 0]).
input_output_vars(half(V,Out),[V],[Out]).
input_output_vars(inc(V,Out),[V],[Out]).
input_output_vars(zero(V,Out),[V],[Out]).
input_output_vars(p(V,Out),[V],[Out]).
input_output_vars(bits(V,Out),[V],[Out]).
input_output_vars(bitIter(V,V6,Out),[V,V6],[Out]).
input_output_vars(if(V,V6,V9,Out),[V,V6,V9],[Out]).

CoFloCo proof output:
Preprocessing Cost Relations
=====================================

#### Computed strongly connected components
0. recursive : [half/2]
1. non_recursive : [p/2]
2. recursive : [inc/2]
3. non_recursive : [zero/2]
4. recursive : [bitIter/3,if/4]
5. non_recursive : [bits/2]
6. non_recursive : [start/3]

#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into half/2
1. SCC is partially evaluated into p/2
2. SCC is partially evaluated into inc/2
3. SCC is partially evaluated into zero/2
4. SCC is partially evaluated into bitIter/3
5. SCC is completely evaluated into other SCCs
6. SCC is partially evaluated into start/3

Control-Flow Refinement of Cost Relations
=====================================

### Specialization of cost equations half/2
* CE 12 is refined into CE [21]
* CE 11 is refined into CE [22]
* CE 10 is refined into CE [23]


### Cost equations --> "Loop" of half/2
* CEs [22] --> Loop 14
* CEs [23] --> Loop 15
* CEs [21] --> Loop 16

### Ranking functions of CR half(V,Out)
* RF of phase [16]: [V-1]

#### Partial ranking functions of CR half(V,Out)
* Partial RF of phase [16]:
- RF of loop [16:1]:
V-1


### Specialization of cost equations p/2
* CE 16 is refined into CE [24]
* CE 15 is refined into CE [25]


### Cost equations --> "Loop" of p/2
* CEs [24] --> Loop 17
* CEs [25] --> Loop 18

### Ranking functions of CR p(V,Out)

#### Partial ranking functions of CR p(V,Out)


### Specialization of cost equations inc/2
* CE 18 is refined into CE [26]
* CE 17 is refined into CE [27]


### Cost equations --> "Loop" of inc/2
* CEs [27] --> Loop 19
* CEs [26] --> Loop 20

### Ranking functions of CR inc(V,Out)
* RF of phase [20]: [V]

#### Partial ranking functions of CR inc(V,Out)
* Partial RF of phase [20]:
- RF of loop [20:1]:
V


### Specialization of cost equations zero/2
* CE 20 is refined into CE [28]
* CE 19 is refined into CE [29]


### Cost equations --> "Loop" of zero/2
* CEs [28] --> Loop 21
* CEs [29] --> Loop 22

### Ranking functions of CR zero(V,Out)

#### Partial ranking functions of CR zero(V,Out)


### Specialization of cost equations bitIter/3
* CE 14 is refined into CE [30,31]
* CE 13 is refined into CE [32,33,34,35,36,37]


### Cost equations --> "Loop" of bitIter/3
* CEs [37] --> Loop 23
* CEs [36] --> Loop 24
* CEs [34] --> Loop 25
* CEs [33] --> Loop 26
* CEs [35] --> Loop 27
* CEs [32] --> Loop 28
* CEs [31] --> Loop 29
* CEs [30] --> Loop 30

### Ranking functions of CR bitIter(V,V6,Out)
* RF of phase [23,24]: [V-1]
* RF of phase [25,26]: [V-1]

#### Partial ranking functions of CR bitIter(V,V6,Out)
* Partial RF of phase [23,24]:
- RF of loop [23:1]:
V/2-1
- RF of loop [24:1]:
V-1
* Partial RF of phase [25,26]:
- RF of loop [25:1]:
V/2-1
- RF of loop [26:1]:
V-1


### Specialization of cost equations start/3
* CE 3 is refined into CE [38,39]
* CE 2 is refined into CE [40,41,42,43,44,45,46,47,48,49,50,51]
* CE 4 is refined into CE [52,53,54,55]
* CE 5 is refined into CE [56,57]
* CE 6 is refined into CE [58,59]
* CE 7 is refined into CE [60,61]
* CE 8 is refined into CE [62,63,64]
* CE 9 is refined into CE [65,66,67,68,69,70]


### Cost equations --> "Loop" of start/3
* CEs [69] --> Loop 31
* CEs [38,39,53,54,55,57,59,61,63,64,67,68,70] --> Loop 32
* CEs [40,41,42,43,44,45,46,47,48,49,50,51,52,56,58,60,62,65,66] --> Loop 33

### Ranking functions of CR start(V,V6,V9)

#### Partial ranking functions of CR start(V,V6,V9)


Computing Bounds
=====================================

#### Cost of chains of half(V,Out):
* Chain [[16],15]: 1*it(16)+1
Such that:it(16) =< 2*Out

with precondition: [V=2*Out,V>=2]

* Chain [[16],14]: 1*it(16)+1
Such that:it(16) =< 2*Out

with precondition: [V=2*Out+1,V>=3]

* Chain [15]: 1
with precondition: [V=0,Out=0]

* Chain [14]: 1
with precondition: [V=1,Out=0]


#### Cost of chains of p(V,Out):
* Chain [18]: 1
with precondition: [V=0,Out=0]

* Chain [17]: 1
with precondition: [V=Out+1,V>=1]


#### Cost of chains of inc(V,Out):
* Chain [[20],19]: 1*it(20)+1
Such that:it(20) =< Out

with precondition: [V=Out,V>=1]

* Chain [19]: 1
with precondition: [V=0,Out=0]


#### Cost of chains of zero(V,Out):
* Chain [22]: 1
with precondition: [V=0,Out=1]

* Chain [21]: 1
with precondition: [Out=0,V>=1]


#### Cost of chains of bitIter(V,V6,Out):
* Chain [[25,26],28,30]: 5*it(25)+5*it(26)+2*s(5)+10
Such that:it(25) =< V/2
aux(5) =< V
aux(6) =< 2*V
it(25) =< aux(5)
it(26) =< aux(5)
it(26) =< aux(6)
s(5) =< aux(6)

with precondition: [V6=0,Out=0,V>=2]

* Chain [[23,24],27,29]: 5*it(23)+5*it(24)+2*s(7)+1*s(17)+2*s(18)+1*s(19)+10
Such that:it(23) =< V/2
aux(14) =< V
aux(15) =< 2*V
aux(16) =< Out+1
s(7) =< aux(16)
it(23) =< aux(14)
it(24) =< aux(14)
s(18) =< aux(15)
it(24) =< aux(15)
aux(9) =< aux(16)
s(17) =< it(23)*aux(16)
s(19) =< it(24)*aux(9)

with precondition: [V6=Out+1,V>=2,V6>=1]

* Chain [30]: 5
with precondition: [V=0,V6=0,Out=0]

* Chain [29]: 1*s(7)+5
Such that:s(7) =< V6

with precondition: [V=0,V6=Out+1,V6>=1]

* Chain [28,30]: 10
with precondition: [V=1,V6=0,Out=0]

* Chain [27,29]: 2*s(7)+10
Such that:aux(7) =< Out+1
s(7) =< aux(7)

with precondition: [V=1,V6=Out+1,V6>=1]


#### Cost of chains of start(V,V6,V9):
* Chain [33]: 10*s(21)+4*s(23)+13*s(27)+20*s(28)+20*s(31)+2*s(42)+2*s(43)+12
Such that:aux(21) =< 2
aux(22) =< V6
aux(23) =< V6/2
aux(24) =< V6/4
aux(25) =< V9
s(23) =< aux(21)
s(27) =< aux(22)
s(28) =< aux(24)
s(21) =< aux(25)
s(28) =< aux(23)
s(31) =< aux(23)
s(31) =< aux(22)
s(41) =< aux(25)
s(42) =< s(28)*aux(25)
s(43) =< s(31)*s(41)

with precondition: [V=0]

* Chain [32]: 3*s(66)+10*s(69)+10*s(72)+4*s(73)+4*s(75)+1*s(84)+1*s(85)+11
Such that:aux(26) =< V
aux(27) =< 2*V
aux(28) =< V/2
aux(29) =< V6
s(66) =< aux(26)
s(69) =< aux(28)
s(69) =< aux(26)
s(72) =< aux(26)
s(72) =< aux(27)
s(73) =< aux(27)
s(75) =< aux(29)
s(83) =< aux(29)
s(84) =< s(69)*aux(29)
s(85) =< s(72)*s(83)

with precondition: [V>=1]

* Chain [31]: 5*s(86)+5*s(89)+2*s(90)+10
Such that:s(87) =< V
s(88) =< 2*V
s(86) =< V/2
s(86) =< s(87)
s(89) =< s(87)
s(89) =< s(88)
s(90) =< s(88)

with precondition: [V6=0,V>=2]


Closed-form bounds of start(V,V6,V9):
-------------------------------------
* Chain [33] with precondition: [V=0]
- Upper bound: nat(V6)*13+20+nat(V9)*10+nat(V9)*2*nat(V6/2)+nat(V9)*2*nat(V6/4)+nat(V6/2)*20+nat(V6/4)*20
- Complexity: n^2
* Chain [32] with precondition: [V>=1]
- Upper bound: 13*V+11+nat(V6)*4+nat(V6)*V+V/2*nat(V6)+8*V+5*V
- Complexity: n^2
* Chain [31] with precondition: [V6=0,V>=2]
- Upper bound: 23/2*V+10
- Complexity: n

### Maximum cost of start(V,V6,V9): max([nat(V6)*13+10+nat(V9)*10+nat(V9)*2*nat(V6/2)+nat(V9)*2*nat(V6/4)+nat(V6/2)*20+nat(V6/4)*20,8*V+1+nat(V6)*4+nat(V6)*V+V/2*nat(V6)+4*V+5/2*V+23/2*V])+10
Asymptotic class: n^2
* Total analysis performed in 399 ms.

(10) BOUNDS(1, n^2)